/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.casestudy1.view;

import com.casestudy1.main.MainMidlet;
import com.casestudy1.yuh.ListTrafficInfoForm;
import com.casestudy1.yuh.SearchByLocalForm;
import com.sun.lwuit.Button;
import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.CoordinateLayout;
import java.io.IOException;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

/**
 *
 * @author Windsea
 */
public class BlockedTrafficForm extends View implements ActionListener {

    private Button btn1, btn2, btn3;
    Command backCommand;

    public BlockedTrafficForm(final MainMidlet midlet) throws IOException, MediaException {
        super(midlet);
        setTitle("Blocked Traffic");
        getStyle().setBgPainter(new LinearGradientPainter(0xff0055, 0xae4ccd, false));
        //set layout

        //init button

        setLayout(new CoordinateLayout(240, 300));

        btn1 = new Button("VOV 91Mhz", midlet.getImage("VOV"));
        btn2 = new Button("List blocked traffic", midlet.getImage("List"));
        btn1.setFlatten(true);
        btn3 = new Button("Search", midlet.getImage("search"));
        btn2.setFlatten(true);
        btn3.setFlatten(true);
        btn2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                new ListTrafficInfoForm(midlet, "all").show();
            }
        });

        btn3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                new SearchByLocalForm(midlet).show();
            }
        });

        btn1.setX(30);
        btn1.setY(20);
        btn2.setX(30);
        btn2.setY(120);
        btn3.setX(50);
        btn3.setY(220);

        btn1.addActionListener(new ActionListener() {
//            private String url = "http://vovgiaothong.vn/giao-thong/diem-nong-giao-thong/";
            public void actionPerformed(ActionEvent evt) {
                try {
                    //                Display.getInstance().execute(url);
                    Player player = Manager.createPlayer("capture://radio?f=91.0&st=stereo");
                    player.start();
                } catch (IOException ex) {
                    ex.printStackTrace();
                } catch (MediaException ex) {
                    ex.printStackTrace();
                }
            }
        });

        backCommand = new Command("Trở lại") {
            public void actionPerformed(ActionEvent evt) {
                midlet.showMainMenu();
            }
        };
        addComponent(btn1);
        addComponent(btn2);
        addComponent(btn3);
        addCommand(backCommand);
        setBackCommand(backCommand);

    }

    public void actionPerformed(ActionEvent ae) {
    }
}
